using RxjhServer.Network;
using System;
using System.Collections;

namespace RxjhServer
{
	public class buzhuoClass : IDisposable
	{
		private double double_0;

		private float float_0;

		private float float_1;

		private float float_2;

		private float float_3;

		private float float_4;

		private float float_5;

		private float float_6;

		private float float_7;

		private int int_0;

		private int a;

		private int b;

		private int c;

		private int d;

		private int e;

		private int f;

		private int int_1;

		private int int_2;

		public Timer npcyd;

		public Players players_0;

		private string string_0;

		private string string_1;

		private ThreadSafeDictionary<int, Players> threadSafeDictionary_0;

		public DateTime time;

		public int FLD_PID
		{
			get
			{
				return int_2;
			}
			set
			{
				int_2 = value;
			}
		}

		public int Gji
		{
			get
			{
				return int_1;
			}
			set
			{
				int_1 = value;
			}
		}

		public string ZrName
		{
			get
			{
				return string_1;
			}
			set
			{
				string_1 = value;
			}
		}

		public buzhuoClass()
		{
			threadSafeDictionary_0 = new ThreadSafeDictionary<int, Players>();
		}

		public buzhuoClass(Players players_1, int int_7)
		{
			threadSafeDictionary_0 = new ThreadSafeDictionary<int, Players>();
			players_0 = players_1;
			method_9(players_1.人物全服ID + 30000);
			method_31(0);
			method_33(0);
			method_27(players_1.人物坐标_地图);
			method_15(players_1.人物坐标_X);
			method_17(players_1.人物坐标_Y);
			method_19(players_1.人物坐标_Z);
			method_1(0f);
			method_3(0f);
			method_11(int_7);
		}

		public void Dispose()
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_Dispose");
			}
			try
			{
				players_0 = null;
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "NPC 关闭数据Dispose() 出错：" + ex?.ToString());
			}
		}

		~buzhuoClass()
		{
		}

		public float method_0()
		{
			return float_0;
		}

		public void method_1(float float_8)
		{
			float_0 = float_8;
		}

		public int method_10()
		{
			return b;
		}

		public void method_11(int int_7)
		{
			b = int_7;
		}

		public double method_12()
		{
			return double_0;
		}

		public void method_13(double double_1)
		{
			double_0 = double_1;
		}

		public float method_14()
		{
			return float_2;
		}

		public void method_15(float float_8)
		{
			float_2 = float_8;
		}

		public float method_16()
		{
			return float_3;
		}

		public void method_17(float float_8)
		{
			float_3 = float_8;
		}

		public float method_18()
		{
			return float_4;
		}

		public void method_19(float float_8)
		{
			float_4 = float_8;
		}

		public float method_2()
		{
			return float_1;
		}

		public float method_20()
		{
			return float_5;
		}

		public void method_21(float float_8)
		{
			float_5 = float_8;
		}

		public float method_22()
		{
			return float_6;
		}

		public void method_23(float float_8)
		{
			float_6 = float_8;
		}

		public float method_24()
		{
			return float_7;
		}

		public void method_25(float float_8)
		{
			float_7 = float_8;
		}

		public int method_26()
		{
			return c;
		}

		public void method_27(int int_7)
		{
			c = int_7;
		}

		public int method_28()
		{
			return d;
		}

		public void method_29(int int_7)
		{
			d = int_7;
		}

		public void method_3(float float_8)
		{
			float_1 = float_8;
		}

		public int method_30()
		{
			return e;
		}

		public void method_31(int int_7)
		{
			e = int_7;
		}

		public int method_32()
		{
			return f;
		}

		public void method_33(int int_7)
		{
			f = int_7;
		}

		public bool method_34(int int_7, Players players_1)
		{
			if (players_1.人物坐标_地图 != method_26())
			{
				return false;
			}
			if (players_0.人物坐标_地图 == 7101)
			{
				int_7 = 1000;
			}
			float num = players_0.人物坐标_X - method_14();
			float num2 = players_0.人物坐标_Y - method_16();
			float num3 = (int)Math.Sqrt(num * num + num2 * num2);
			return num3 <= (float)int_7;
		}

		public void method_35(int int_7)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_获取范围玩家发送增加数据包");
			}
			method_27(players_0.人物坐标_地图);
			try
			{
				foreach (Players value in World.allConnectedChars.Values)
				{
					if (method_34(400, value))
					{
						method_37(value);
						if (int_7 == 1)
						{
							method_36(value);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "获取范围玩家发送地面增加Npc数据包 出错：" + ex?.ToString());
			}
		}

		public void method_36(Players players_1)
		{
			using (发包类 发包类 = new 发包类())
			{
				发包类.Write4(1);
				发包类.Write2(method_8());
				发包类.Write2(method_8());
				发包类.Write2(method_10());
				发包类.Write4(1);
				发包类.Write4(-1);
				发包类.Write4(-1);
				发包类.Write(method_14());
				发包类.Write(method_18());
				发包类.Write(method_16());
				发包类.Write4(1082130432);
				发包类.Write(method_0());
				发包类.Write(method_2());
				发包类.Write(method_14());
				发包类.Write(method_18());
				发包类.Write(method_16());
				发包类.Write4(0);
				发包类.Write4(0);
				发包类.Write4(12);
				发包类.Write4(0);
				if (players_1.Client != null)
				{
					players_1.Client.SendPak(发包类, 26368, players_1.人物全服ID);
				}
			}
		}

		public void method_37(Players players_1)
		{
			using (发包类 发包类 = new 发包类())
			{
				发包类.Write4(1);
				发包类.Write2(method_8());
				发包类.Write2(method_8());
				发包类.Write2(method_10());
				发包类.Write4(1);
				发包类.Write4(-1);
				发包类.Write4(-1);
				发包类.Write(method_14());
				发包类.Write(method_18());
				发包类.Write(method_16());
				发包类.Write4(1082130432);
				发包类.Write(method_0());
				发包类.Write(method_2());
				发包类.Write(method_14());
				发包类.Write(method_18());
				发包类.Write(method_16());
				发包类.Write4(0);
				发包类.Write4(0);
				发包类.Write4(12);
				发包类.Write4(0);
				if (players_1.Client != null)
				{
					players_1.Client.SendPak(发包类, 26624, players_1.人物全服ID);
				}
			}
		}

		private void method_38(Players players_1)
		{
			using (发包类 pak = new 发包类())
			{
				if (players_1.Client != null)
				{
					players_1.Client.SendPak(pak, 34816, method_8());
				}
			}
		}

		public void method_39(float float_8, float float_9, int int_7, int int_8)
		{
			if (World.jlMsg == 1)
			{
				Form1.WriteLine(1, "NpcClass_发送移动数据");
			}
			try
			{
				using (发包类 发包类 = new 发包类())
				{
					Random random = new Random();
					int num = random.Next(0, 2);
					double num2 = random.NextDouble() * (double)int_7;
					double num3 = random.NextDouble() * (double)int_7;
					if (num == 0)
					{
						method_15(float_8 + (float)num2);
						method_17(float_9 + (float)num3);
					}
					else
					{
						method_15(float_8 - (float)num2);
						method_17(float_9 - (float)num3);
					}
					发包类.Write(method_14());
					发包类.Write(method_16());
					发包类.Write(method_18());
					发包类.Write4(-1);
					发包类.Write4(int_8);
					发包类.Write((float)num2);
					发包类.Write4(method_32());
					players_0.Client.SendPak(发包类, 29696, method_8());
					players_0.发送当前范围广播数据(发包类, 29696, method_8());
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "发送移动数据 出错" + method_10().ToString() + "|" + method_6() + " " + ex.Message);
			}
		}

		public int method_4()
		{
			return int_0;
		}

		public void method_5(int int_7)
		{
			int_0 = int_7;
		}

		public string method_6()
		{
			return string_0;
		}

		public void method_7(string string_1)
		{
			string_0 = string_1;
		}

		public int method_8()
		{
			return a;
		}

		public void method_9(int int_7)
		{
			a = int_7;
		}

		public void 发送当前范围广播数据(发包类 发包类_0, int int_1, int wordid)
		{
			try
			{
				if (threadSafeDictionary_0 != null)
				{
					Queue queue = Queue.Synchronized(new Queue());
					foreach (Players value in threadSafeDictionary_0.Values)
					{
						queue.Enqueue(value);
					}
					while (queue.Count > 0)
					{
						if (World.jlMsg == 1)
						{
							Form1.WriteLine(1, "发送当前范围广播数据");
						}
						Players players = (Players)queue.Dequeue();
						if (players.Client != null)
						{
							if (players.Client.Running)
							{
								players.Client.SendPak(发包类_0, int_1, wordid);
							}
							else
							{
								threadSafeDictionary_0.Remove(players.人物全服ID);
								if (players.Client != null)
								{
									players.Client.Dispose();
								}
							}
						}
						else
						{
							threadSafeDictionary_0.Remove(players.人物全服ID);
							if (players.Client != null)
							{
								players.Client.Dispose();
							}
						}
						if (!World.allConnectedChars.ContainsKey(players.Client.WorldId))
						{
							if (players.Client != null)
							{
								players.Client.Dispose();
							}
							threadSafeDictionary_0.Remove(players.人物全服ID);
						}
					}
				}
			}
			catch (Exception ex)
			{
				Form1.WriteLine(1, "NPC广播数据 出错3：" + ex?.ToString());
			}
		}
	}
}
